package
{
	import com.jidolstar.astro.*;	
	import flash.display.Sprite;

	/**
	 * 천문관련 시간변환 테스트 
	 * @author Yongho, Ji
	 * @since 2009.05.12
	 */ 
	public class testTimeConverter extends Sprite
	{
		public function testTimeConverter()
		{
			super();
			
			trace( "================================ test TimeConverter ====================================");
			trace( "current JD : " + ALTimeConverter.currentJD ); //current JD : 2454931.5618515974
			trace( "current JDE: " + ALTimeConverter.currentJDE ); //current JDE: 2454931.56261997

			//-----------------------------------------------------------------------
			// Astronomical Algorithms 2nd page.88 Example 12.a
			//-----------------------------------------------------------------------
			var JD:Number = 2446895.5; //2446895.5
			var JDE:Number = ALTimeConverter.JD2JDE( JD );
			var nutation:ALNutation = new ALNutation( JDE, ALNutation.HIGH_ACCURACY, ALNutation.LONG_PERIOD );
			var obsLongitude:Number = 126.9669; 
			trace( "JD : " + JD ); //JD : 2446895.5
			trace( "JDE: " + nutation.JDE ); //JDE: 2446895.500641634
			trace( "accurcy: " + nutation.accuracy ); //accurcy: highAccuracy
			trace( "peroid: " + nutation.period ); //peroid: longPeriod			
			trace( "Δψ : " + nutation.nutationInLongitude * ALConst.R2S); //Δψ : -3.7879706538588125
			trace( "Δε : " + nutation.nutationInObliquity * ALConst.R2S); //Δε : 9.442541705919625
			trace( "ε0 : " + ALDMS.fractionalDegree2DMS( nutation.meanObliquityOfEcliptic * ALConst.R2D ).toString() ); //ε0 : 23° 26’ 27”.37
			trace( "ε  : " + ALDMS.fractionalDegree2DMS( nutation.trueObliquityOfEcliptic * ALConst.R2D ).toString() ); //ε  : 23° 26’ 36”.81
			trace( "observer longitude : " +  ALDMS.fractionalDegree2DMS( obsLongitude ).toString() ); //observer longitude : 126° 58’ 00”.84

			//Greenwich Mean Sidereal Time
			var GMST:Number =  ALTimeConverter.JD2GMST( JD );
			trace( "GMST : " + ALHMS.fractionalHour2HMS( GMST * ALConst.R2H).toString("h","m","s", 4) ); //GMST : 13h10m46.3668s
			
			//Greenwich Apparent Sidereal Time 
			var GAST:Number = ALTimeConverter.JD2GAST( JD, nutation.nutationInLongitude, nutation.trueObliquityOfEcliptic );
			trace( "GAST : " + ALHMS.fractionalHour2HMS( GAST * ALConst.R2H).toString("h","m","s", 4) ); //GAST : 13h10m46.1351s
			
			//Local Mean Sidereal Time
			var LMST:Number = ALTimeConverter.JD2LMST( JD, obsLongitude );
			trace( "LMST : " + ALHMS.fractionalHour2HMS( LMST * ALConst.R2H).toString("h","m","s", 4) ); //LMST : 21h38m38.4228s
			
			//Local Apparent Sidereal Time 
			var LAST:Number = ALTimeConverter.JD2LAST( JD, obsLongitude, nutation.nutationInLongitude, nutation.trueObliquityOfEcliptic );
			trace( "LAST : " + ALHMS.fractionalHour2HMS( LAST * ALConst.R2H).toString("h","m","s", 4) ); //LAST : 21h38m38.1911s
			
			//-----------------------------------------------------------------------
			// 1987-04-10 19:21:00 UT, Astronomical Algorithms 2nd page.89 Example 12.a
			//-----------------------------------------------------------------------
			var date:ALDate = new ALDate( 1987, 4, 10, 19, 21, 0 );
			JD = date.JD;
			JDE = ALTimeConverter.JD2JDE( JD );
			nutation.JDE = JDE;
			trace( "-------------------------" );
			trace( "Date " + date.toString( 2 ) ); //1987-04-10 19:20:60.00
			trace( "JD : " + JD ); //JD : 2446896.30625
			trace( "JDE: " + nutation.JDE ); //JDE: 2446896.306891646
			trace( "accurcy: " + nutation.accuracy ); //accurcy: highAccuracy
			trace( "peroid: " + nutation.period ); //peroid: longPeriod			
			trace( "Δψ : " + nutation.nutationInLongitude * ALConst.R2S); //Δψ : -3.867334308485008
			trace( "Δε : " + nutation.nutationInObliquity * ALConst.R2S); //Δε : 9.465177058355563
			trace( "ε0 : " + ALDMS.fractionalDegree2DMS( nutation.meanObliquityOfEcliptic * ALConst.R2D ).toString() ); //ε0 : 23° 26’ 27”.37
			trace( "ε  : " + ALDMS.fractionalDegree2DMS( nutation.trueObliquityOfEcliptic * ALConst.R2D ).toString() ); //ε  : 23° 26’ 36”.83
			trace( "observer longitude : " +  ALDMS.fractionalDegree2DMS( obsLongitude ).toString() ); //observer longitude : 126° 58’ 00”.84

			
			//Greenwich Mean Sidereal Time
			GMST =  ALTimeConverter.JD2GMST( JD );
			trace( "GMST : " + ALHMS.fractionalHour2HMS( GMST * ALConst.R2H).toString("h","m","s", 4) ); //GMST : 08h34m57.0896s
			
			//Greenwich Apparent Sidereal Time 
			GAST = ALTimeConverter.JD2GAST( JD, nutation.nutationInLongitude, nutation.trueObliquityOfEcliptic );
			trace( "GAST : " + ALHMS.fractionalHour2HMS( GAST * ALConst.R2H).toString("h","m","s", 4) ); //GAST : 08h34m56.8530s
			
			//Local Mean Sidereal Time
			LMST = ALTimeConverter.JD2LMST( JD, obsLongitude );
			trace( "LMST : " + ALHMS.fractionalHour2HMS( LMST * ALConst.R2H).toString("h","m","s", 4) ); //LMST : 17h02m49.1456s
			
			//Local Apparent Sidereal Time 
			LAST = ALTimeConverter.JD2LAST( JD, obsLongitude, nutation.nutationInLongitude, nutation.trueObliquityOfEcliptic );
			trace( "LAST : " + ALHMS.fractionalHour2HMS( LAST * ALConst.R2H).toString("h","m","s", 4) ); //LAST : 17h02m48.9090s
			
			//-----------------------------------------------------------------------
			// 2009-04-10 16:50:40 KST(-540 minutes=-9 hours)
			//-----------------------------------------------------------------------			
			var calendarDate:ALCalendarDate = new ALCalendarDate( 2009, 4, 10, 16, 50, 40 );
			var timezoneOffset:Number = -540; //KST (-540 minutes=-9 hours)
			obsLongitude = 126.9997; //관측자 경도 
			JD = ALTimeConverter.LCT2JD( calendarDate.year, calendarDate.month, calendarDate.fractionalDay, timezoneOffset );
			date = new ALDate( JD );
			JDE = ALTimeConverter.JD2JDE( JD );
			nutation = new ALNutation( JDE, ALNutation.HIGH_ACCURACY, ALNutation.LONG_PERIOD );
			trace( "-------------------------" );
			trace( "Local Date " + calendarDate.toString( 2 ) ); //Local Date 2009-04-10 16:50:40.00
			trace( "Greenwitch Date " + date.toString( 2 ) ); //Greenwitch Date 2009-04-10 07:50:40.00
			trace( "JD : " + JD.toFixed(20) ); //JD : 2454931.826851852
			trace( "JDE: " + nutation.JDE ); //JDE: 2454931.827620228
			trace( "ΔT: " + ALDynamicalTime.deltaT( calendarDate.fractionalYear ) ); //ΔT: 66.38731983324448
			trace( "accurcy: " + nutation.accuracy ); //accurcy: highAccuracy
			trace( "peroid: " + nutation.period ); //peroid: longPeriod	
			trace( "Δψ : " + nutation.nutationInLongitude * ALConst.R2S); //Δψ : 12.90094655362135
			trace( "Δε : " + nutation.nutationInObliquity * ALConst.R2S); //Δε : 5.87692711963493
			trace( "ε0 : " + ALDMS.fractionalDegree2DMS( nutation.meanObliquityOfEcliptic * ALConst.R2D ).toString() ); //ε0 : 23° 26’ 17”.07
			trace( "ε  : " + ALDMS.fractionalDegree2DMS( nutation.trueObliquityOfEcliptic * ALConst.R2D ).toString() ); //ε  : 23° 26’ 22”.95
			trace( "observer longitude : " +  ALDMS.fractionalDegree2DMS( obsLongitude ).toString() ); //observer longitude : 126° 59’ 58”.92
			
			//Greenwich Mean Sidereal Time
			GMST =  ALTimeConverter.LCT2GMST( calendarDate.year, calendarDate.month, calendarDate.fractionalDay, timezoneOffset );
			trace( "GMST : " + ALHMS.fractionalHour2HMS( GMST * ALConst.R2H).toString("h","m","s", 4) ); //GMST : 21h05m22.6212s
			
			//Greenwich Apparent Sidereal Time 
			GAST = ALTimeConverter.LCT2GAST( calendarDate.year, calendarDate.month, calendarDate.fractionalDay, timezoneOffset, nutation.nutationInLongitude, nutation.trueObliquityOfEcliptic );
			trace( "GAST : " + ALHMS.fractionalHour2HMS( GAST * ALConst.R2H).toString("h","m","s", 4) ); //GAST : 21h05m23.4103s
			
			//Local Mean Sidereal Time
			LMST = ALTimeConverter.LCT2LMST( calendarDate.year, calendarDate.month, calendarDate.fractionalDay, timezoneOffset, obsLongitude );
			trace( "LMST : " + ALHMS.fractionalHour2HMS( LMST * ALConst.R2H).toString("h","m","s", 4) ); //LMST : 05h33m22.5492s
			
			//Local Apparent Sidereal Time 
			LAST = ALTimeConverter.LCT2LAST( calendarDate.year, calendarDate.month, calendarDate.fractionalDay, timezoneOffset, obsLongitude, nutation.nutationInLongitude, nutation.trueObliquityOfEcliptic );
			trace( "LAST : " + LAST + "," + ALHMS.fractionalHour2HMS( LAST * ALConst.R2H).toString("h","m","s", 4) ); //LAST : 05h33m23.3383s

		}
		
	}
}